<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form id="form_role_showedit" method="post" action="../../shiro/role/editRole.action">
    <input type="hidden" name="roleId" value="${role.roleId==null?0:role.roleId}">
    <input type="hidden" name="permissionstrs" value="${role.permissionstrs}">
    <input type="hidden" name="menuIdstrs" value="${role.menuIdstrs}">
    <table class="tab_form">
        <tr>
            <td><input class="easyui-textbox" name="rolename" data-options="label:'角色名称:',required:true"
                       value="${role.rolename}"/></td>
        </tr>
        <tr>
            <td>
                <ul id="role_tree" data-options="checkbox:true,cascadeCheck:false"></ul>
            </td>
        </tr>
    </table>
</form>
<div style="text-align:center;padding:5px 0">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">保存</a>
</div>
<script>
    $(function () {
        initTree();
    });
    function initTree() {
        $("#role_tree").tree({
            url:'../../shiro/role/loadTreeData.action',
            onLoadSuccess:function (node,data) {
                var menuIdstrs = $("input[name=menuIdstrs]").val();
                var items = menuIdstrs.split(",");
                if(items.length>0){
                    for(var i=0;i<items.length;i++){
                        var node = $('#role_tree').tree('find', items[i]);
                        $('#role_tree').tree('check', node.target);
                    }
                }
            }
        });
    }
    function setPermissionstrs() {
        var nodes = $('#role_tree').tree('getChecked');
        var permissionstrs = "";
        for(var i=0;i<nodes.length;i++){
            if(i==nodes.length){
                permissionstrs +=nodes[i].attributes.menupermission+"$"+nodes[i].attributes.menuId;
            }else{
                permissionstrs +=nodes[i].attributes.menupermission+"$"+nodes[i].attributes.menuId+",";
            }
        }
        $("input[name=permissionstrs]").val(permissionstrs);
    }
    function submitForm() {
        setPermissionstrs();
        $('#form_role_showedit').form('submit', {
            success: function () {
                $('#win_main').window("close");
                $("#role_list").datagrid("reload");
            }
        });
    }
    function clearForm() {
        $('#form_role_showedit').form('clear');
    }
</script>